//aes加密
function aes_encrypt(word) {
	let keyStr = "hyhs" + new Date().toISOString().slice(0, 10).replaceAll('-', '') + "hsst"; //加密密钥
	let ivStr = "abcdefghijklmnop"; //矢量
	var key = CryptoJS.enc.Utf8.parse(keyStr);
	var iv = CryptoJS.enc.Utf8.parse(ivStr);
	// var srcs = CryptoJS.enc.Utf8.parse(word);
	var encrypted = CryptoJS.AES.encrypt(word, key, {
		iv: iv,
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}

// aes解密
function aes_Decrypt(word, key) {
	var key = CryptoJS.enc.Utf8.parse(key) //转为128bit
	var srcs = CryptoJS.enc.Hex.parse(word) //转为16进制
	var str = CryptoJS.enc.Base64.stringify(srcs) //变为Base64编码的字符串
	var decrypt = CryptoJS.AES.decrypt(str, key, {
		mode: CryptoJS.mode.ECB,
		spadding: CryptoJS.pad.Pkcs7
	})
	return decrypt.toString(CryptoJS.enc.Utf8)
}


//导出函数
module.exports = {
	aes_encrypt,
	aes_Decrypt
}
